﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Vit.Common.Extensions;

namespace Vit.Web.Extensions
{
    public static class ObjectExtenstions
    {
        public static string FormatWithProperies(this object obj, string format)
        {
            if (obj == null)
                return format;
            List<string> props = format.ToList("{", "}");
            if (props.Count > 0)
            {
                Dictionary<string, string> vals = new Dictionary<string, string>();
                foreach (string prop in props)
                {
                    object val = obj.GetPropertyValue(prop.TrimStart('{').TrimEnd('}'));

                    vals.Add(prop, val == null ? "" : val.ToString());
                }
                format = format.Replace(vals);
            }
            return format;
        }
    }
}
